Skip to content

Conversation

@wolfv
Copy link
Member

@wolfv wolfv commented Nov 11, 2025

Trying to finish the PR using Claude

Armd04 and others added 22 commits September 20, 2024 01:42
Merge branch 'pr-155' to add support for unary arithmetic operators
including increment (++) and decrement (--) in both prefix and postfix forms.

Resolved conflicts in:
- parser.rs: Unified UnaryArithmeticExpr structure with Pre/Post variants
- execute.rs: Updated evaluation logic for new operator structure
- types.rs: Added unary_op method for pre/post increment/decrement

The implementation now supports expressions like:
- ++a (pre-increment)
- a++ (post-increment)
- --a (pre-decrement)
- a-- (post-decrement)
Fixed the following issues raised in code review:

1. Added validation to reject increment/decrement on literal numbers
   - Now correctly errors on expressions like `echo $(++2)`
   - Operators can only be applied to variables or parenthesized expressions

2. Replaced .unwrap() calls with proper error handling
   - Fixed unwrap() in unary_pre_arithmetic_expr (line 1738)
   - Fixed unwrap() in unary_post_arithmetic_expr (line 1783)
   - Used ok_or_else() with descriptive error messages

3. Fixed missing parse_variable_expansion function
   - Restored function that was accidentally removed during merge
   - Fixes compilation errors

4. Fixed stray conflict marker in types.rs
   - Removed leftover "<<<<<<< HEAD" marker

All tests pass and manual testing confirms:
- Post-increment (a++) returns original value, updates variable
- Pre-increment (++a) returns new value, updates variable
- Invalid expressions like ++2 correctly produce errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants